package com.inifitness.tenant.core.filter;

import jakarta.servlet.http.HttpServletRequest;

import lombok.extern.log4j.Log4j2;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CommonsRequestLoggingFilter;

/**
 * 请求日志打印过滤器
 *
 * @author sunjinfeng
 * @since 2023/03/03
 */
@Configuration
@Log4j2
public class RequestLogFilter extends CommonsRequestLoggingFilter {

  @Override
  protected boolean shouldLog(@NotNull HttpServletRequest request) {
    // 设置日志输出级别，默认debug
    return this.logger.isInfoEnabled();
  }

  @Override
  protected void beforeRequest(HttpServletRequest request, @NotNull String message) {
    String requestUri = request.getRequestURI();
    log.info("request uri: {}", requestUri);
    super.beforeRequest(request, message);
  }
}
